<script type="text/x-template" id="documentmanager">
    <div>
        <el-container>
            <el-header>
                <div style="padding: 10px;height: 50px">
                    <el-form :model="searchform"  label-width="100px" class="demo-ruleForm">
                        <el-row>
                            <el-col :span="7">
                                <el-form-item label="栏目名称" >
                                    <el-input v-model="input" placeholder="请输入内容"></el-input>
                                </el-form-item>
                            </el-col>
                            <el-col :span="7">
                                <el-form-item label="栏目名称" >
                                    <el-input v-model="input" placeholder="请输入内容"></el-input>
                                </el-form-item>
                            </el-col>
                            <el-col :span="7">
                                <el-form-item label="栏目名称" >
                                    <el-input v-model="input" placeholder="请输入内容"></el-input>
                                </el-form-item>
                            </el-col>
                            <el-col :span="3">
                                <div align="center">
                                    <el-button type="primary">搜索</el-button>
                                </div>
                            </el-col>
                        </el-row>
                    </el-form>
                </div>
            </el-header>
            <el-container>
                <el-aside width="15%">
                    <div style="padding: 10px">
                        <el-button type="primary" icon="el-icon-edit" style="width: 100%" @click="addfilegroup">新建分组</el-button>
                        <!--  树-->
                        <el-tree :data="data" :props="defaultProps" @node-click="handleNodeClick" style="padding-top: 5px"></el-tree>
                    </div>
                </el-aside>
                <el-container>
                    <el-main>
                        <div style="padding-bottom: 10px">
                            <el-button-group>
                                <el-upload
                                        @click="uploadfile"
                                        ref="upload"
                                        class="upload-demo"
                                        action="/document/add"
                                        :headers="heards"
                                        :data="updataData"
                                        multiple
                                        :limit="1"
                                        :auto-upload="false"
                                        :on-change="handleUploadChange"
                                        :on-success="uploadsuccess"
                                        :file-list="fileList">
                                    <el-button  type="primary">点击上传</el-button>
                                </el-upload>
                            </el-button-group>
                        </div>
                        <template>
                            <el-table
                                    :data="tableDatas_res"
                                    stripe
                                    style="width: 100%;min-height: 500px">
                                <el-table-column
                                        type="selection"
                                        width="55">
                                </el-table-column>
                                <el-table-column
                                        :show-overflow-tooltip="true"
                                        prop="filename"
                                        label="文件名"
                                        width="250">
                                </el-table-column>
                                <el-table-column
                                        :show-overflow-tooltip="true"
                                        prop="filetye"
                                        label="文件类型"
                                        width="180">
                                </el-table-column>
                                <el-table-column
                                        :show-overflow-tooltip="true"
                                        prop="note"
                                        label="文件备注"
                                        width="200">
                                </el-table-column>
                                <el-table-column
                                        prop="fileSize"
                                        label="文件长度">
                                </el-table-column>
                                <el-table-column
                                        fixed="right"
                                        label="操作"
                                        width="200">
                                    <template slot-scope="scope">
                                        <el-button @click="donloadClick(scope.row)" type="text" size="small">下载</el-button>
                                        <el-button @click="handleDeleteClick(scope.row)" type="text" size="small">删除</el-button>
                                    </template>
                                </el-table-column>
                            </el-table>
                        </template>

                        <el-divider></el-divider>

                        <el-pagination
                                background
                                @current-change="handleCurrentChange_respage"
                                layout="total,prev, pager, next"
                                :total="total">
                        </el-pagination>

                    </el-main>
                </el-container>
            </el-container>
        </el-container>

        <!-- 添加上传的文件        -->
        <el-dialog title="添加上传文件的备注" :visible.sync="dialogFormVisible_addpane">

            <div>
                <el-input v-model="updataData.note" placeholder="请输入内容"></el-input>
            </div>


            <div slot="footer" class="dialog-footer">
                <el-button @click="dialogFormVisible_addpane = false">取 消</el-button>
                <el-button type="primary" @click="submitdocument">确 定</el-button>
            </div>
        </el-dialog>

        <!-- 添加分组        -->
        <el-dialog title="添加分组" :visible.sync="dialogFormVisible_addgroup">

        </el-dialog>

    </div>
</script>

<script>
    let documentmanager={
        data() {
            return {
                pageNum:0,
                isupload:true,
                updataData:{},
                heards:{},
                fileList:[],
                multipleSelection:[],
                searchform:{},
                activeName_addfile:'first_addfilepath',
                dialogFormVisible_addpane:false,
                dialogFormVisible_addgroup : false,
                activeIndex: '1',
                activeIndex2: '1',
                total:0,
                input:'',
                filepath:'',
                tableDatas_res: [],
                search:'',
                keyword:'',
                data: [{
                    label: '一级 1',
                    children: [{
                        label: '二级 1-1',
                        children: [{
                            label: '三级 1-1-1'
                        }]
                    }]
                }, {
                    label: '一级 2',
                    children: [{
                        label: '二级 2-1',
                        children: [{
                            label: '三级 2-1-1'
                        }]
                    }, {
                        label: '二级 2-2',
                        children: [{
                            label: '三级 2-2-1'
                        }]
                    }]
                }, {
                    label: '一级 3',
                    children: [{
                        label: '二级 3-1',
                        children: [{
                            label: '三级 3-1-1'
                        }]
                    }, {
                        label: '二级 3-2',
                        children: [{
                            label: '三级 3-2-1'
                        }]
                    }]
                }],
                defaultProps: {
                    children: 'children',
                    label: 'label'
                }
            }
        },
        template: '#documentmanager',
        created(){
            this.pageNum=1;
            this.page(this.pageNum);
        },
        methods: {
            handleDeleteClick(row){
                this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    api.GET('/document/delete',{'id':row.id},(result)=> {
                        if(result.code==0){
                            this.$message({
                                showClose: true,
                                message: '删除成功',
                                type: 'success'
                            });
                            this.page(this.pageNum);
                        }
                    })
                }).catch(() => {
                    this.$message({
                        type: 'info',
                        message: '已取消删除'
                    });
                });
            },
            submitdocument(){
                this.isupload=false;
                this.dialogFormVisible_addpane=false;
                this.updataData={};
                this.$refs.upload.submit();
            },
            uploadsuccess(response, file, fileList){
                if(response.code===0){
                  //  this.isupload=true;
                    this.fileList=[];
                }
            },
            uploadfile(){
                this.dialogFormVisible_addpane=true;
            },
            handleUploadChange(file, fileList){
                if(this.isupload ){
                    this.dialogFormVisible_addpane=true;
                }
            },
            handleClick(row){

            },
            handleCurrentChange_respage(val){
                this.pageNum=val;
                this.page(val);
            },
            page(val){
                api.GET('/document/list',{'pageNum':val,'pageSize':10},(result)=> {
                    this.tableDatas_res=result.data.records;
                    this.total=result.data.total;
                })
            },
            donloadClick(row){
                const a = document.createElement('a');
                a.href =row.downloadUrl;
                a.download = '';
                a.style.display = 'none';
                document.body.appendChild(a);
                a.click();
                document.body.removeChild(a);
            },
            addfilepath(){
                if(this.filepath==''){
                    return this.$message('文件路径必传');
                }
                api.POST('/mfile/scan',{'filepath':this.filepath},(res)=>{

                })
            },
            handleSelectionChangeRes(val){
                this.multipleSelection = val;
            },
            handleClick_file(tab, event){
                console.log(tab, event);
            },
            handleSelect(key, keyPath) {
                console.log(key, keyPath);
            },
            addfilepane(){
                this.dialogFormVisible_addpane=true;
            },
            addfilegroup(){
                this.dialogFormVisible_addgroup=true;
            },
            locationfref(href){
                window.open(href);
            },
            handleNodeClick(data) {
                console.log(data);
            },
            locationppreview(id){
                window.open('/page/contentinfo.html?obj='+id)
            },
            updateNote(id){
                window.open('/page/update.html?obj='+id)
            },
            handleNodeClick(data) {
                console.log(data);
            },
            deleteNote(id){
                this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    api.GET('/note/delete',{'id':id},(result)=> {
                        if(result.code==0){
                            this.$message({
                                showClose: true,
                                message: '删除成功',
                                type: 'success'
                            });
                            local.reload();
                        }
                    })
                }).catch(() => {
                    this.$message({
                        type: 'info',
                        message: '已取消删除'
                    });
                });
            }
        }
    }
    Vue.component('documentmanager',documentmanager);
</script>